{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d7254eee",
   "metadata": {},
   "source": [
    "数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3a0e7d1f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(569, 30)\n",
      "[[1.799e+01 1.038e+01 1.228e+02 ... 2.654e-01 4.601e-01 1.189e-01]\n",
      " [2.057e+01 1.777e+01 1.329e+02 ... 1.860e-01 2.750e-01 8.902e-02]\n",
      " [1.969e+01 2.125e+01 1.300e+02 ... 2.430e-01 3.613e-01 8.758e-02]\n",
      " ...\n",
      " [1.660e+01 2.808e+01 1.083e+02 ... 1.418e-01 2.218e-01 7.820e-02]\n",
      " [2.060e+01 2.933e+01 1.401e+02 ... 2.650e-01 4.087e-01 1.240e-01]\n",
      " [7.760e+00 2.454e+01 4.792e+01 ... 0.000e+00 2.871e-01 7.039e-02]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.svm import SVC\n",
    "from sklearn.svm import SVR\n",
    "\n",
    "from sklearn.datasets import load_breast_cancer\t\n",
    "from sklearn.svm import SVC\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "x,y=load_breast_cancer().data,load_breast_cancer().target\n",
    "print(x.shape)\n",
    "print(x)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a7840ad",
   "metadata": {},
   "source": [
    "使用核函数训练模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9690568c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.09706398 -2.07333501  1.26993369 ...  2.29607613  2.75062224\n",
      "   1.93701461]\n",
      " [ 1.82982061 -0.35363241  1.68595471 ...  1.0870843  -0.24388967\n",
      "   0.28118999]\n",
      " [ 1.57988811  0.45618695  1.56650313 ...  1.95500035  1.152255\n",
      "   0.20139121]\n",
      " ...\n",
      " [ 0.70228425  2.0455738   0.67267578 ...  0.41406869 -1.10454895\n",
      "  -0.31840916]\n",
      " [ 1.83834103  2.33645719  1.98252415 ...  2.28998549  1.91908301\n",
      "   2.21963528]\n",
      " [-1.80840125  1.22179204 -1.81438851 ... -1.74506282 -0.04813821\n",
      "  -0.75120669]]\n",
      "选择linear核函数时，模型的预测准确率为: 0.9766081871345029\n",
      "选择poly核函数时，模型的预测准确率为: 0.9649122807017544\n",
      "选择rbf核函数时，模型的预测准确率为: 0.9707602339181286\n",
      "选择sigmoid核函数时，模型的预测准确率为: 0.9532163742690059\n"
     ]
    }
   ],
   "source": [
    "#数据标准化处理\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "x=StandardScaler().fit_transform(x)\n",
    "print(x)\n",
    "\n",
    "#分割数据集\n",
    "from sklearn.metrics import accuracy_score\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=420)\n",
    "Kernel=[\"linear\",\"poly\",\"rbf\",\"sigmoid\"]\n",
    "for kernel in Kernel:\n",
    "   model=SVC(kernel=kernel,gamma=\"auto\",degree=1)\n",
    "   model.fit(x_train,y_train)\n",
    "   pred=model.predict(x_test)\n",
    "   ac=accuracy_score(y_test,pred)\n",
    "   print(f\"选择{kernel}核函数时，模型的预测准确率为: {ac}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2e5415f",
   "metadata": {},
   "source": [
    "多项式核函数参数的调节"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8ed4f45",
   "metadata": {},
   "source": [
    "数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f5f1f469",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_breast_cancer\t\t\t\t\t                    #导入肺癌数据集\n",
    "from sklearn.svm import SVC              #导入支持向量机分类模块\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "x,y=load_breast_cancer().data,load_breast_cancer().target \n",
    "x=StandardScaler().fit_transform(x)  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed7b2a0e",
   "metadata": {
    "notebookRunGroups": {
     "groupValue": "2"
    }
   },
   "source": [
    "训练模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "37df347b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最优参数值为：{'coef0': np.float64(0.0), 'gamma': np.float64(0.18329807108324375)}\n",
      "选取该参数值时，模型的预测准确率为：0.9695906432748538\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import StratifiedShuffleSplit  #导入分层抽样方法\n",
    "from sklearn.model_selection import GridSearchCV\t\t    #导入网格搜索方法\n",
    "\n",
    "\n",
    "gamma_range=np.logspace(-10,1,20)\n",
    "coef0_range=np.linspace(0,5,10)\n",
    "param_grid=dict(gamma=gamma_range,coef0=coef0_range)\n",
    "cv=StratifiedShuffleSplit(n_splits=5,test_size=0.3,random_state=420)\t\t                                       #对样本进行分层抽样\n",
    "grid=GridSearchCV(SVC(kernel=\"poly\",degree=1),\n",
    "param_grid=param_grid,cv=cv)\t                              #使用网格搜索法寻找参数的最优值\n",
    "grid.fit(x,y)\n",
    "\n",
    "\n",
    "print(f\"最优参数值为：{grid.best_params_}\")\n",
    "print(f\"选取该参数值时，模型的预测准确率为：{grid.best_score_}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2229ea4b",
   "metadata": {},
   "source": [
    "使用高斯径向基核函数进行参数的调节"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d07c30a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiwAAAGdCAYAAAAxCSikAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjcsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvTLEjVAAAAAlwSFlzAAAP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CYII=",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "参数gamma的最优值为：0.012067926406393264\n",
      "选取该参数值时，模型的预测准确率为：0.976608\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=420)\t\t\t\t\t#分割数据集\n",
    "score=[]\n",
    "gamma_range=np.logspace(-10,1,50)\n",
    "for i in gamma_range:\n",
    "    model=SVC(kernel='rbf',gamma=i)\n",
    "    model.fit(x_train,y_train)\n",
    "    pred=model.predict(x_test)\n",
    "    ac=accuracy_score(y_test,pred)\n",
    "    score.append(ac)\n",
    "\n",
    "\n",
    "plt.plot(gamma_range,score)\n",
    "plt.show()\n",
    "\n",
    "print(f\"参数gamma的最优值为：{gamma_range[score.index(max(score))]}\")\n",
    "print(f\"选取该参数值时，模型的预测准确率为：{max(score)}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "AIG241",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
